package com.aboverock.module.system.service.impl;

import com.aboverock.module.system.domain.Bunit;
import com.aboverock.module.system.mapper.BunitMapper;
import com.aboverock.module.system.service.BunitService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

// import com.aboverock.datalake.enums.DatalakeDataTypeEnum;
// import com.aboverock.datalake.exceptions.DatalakeDataParseException;
// import com.aboverock.datalake.exceptions.DatalakeRequestException;
// import com.aboverock.module.datalake.service.DatalakeService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Rock Wang
 * @since 2018-07-25
 */
@Service
public class BunitServiceImpl extends ServiceImpl<BunitMapper, Bunit> implements BunitService {

    // @Autowired
    // private DatalakeService datalakeService;

    @Override
    public Bunit selectByBunitNo(String bunitNo) {
        return this.getOne(new QueryWrapper<Bunit>().eq("bunit_no", bunitNo));
    }

    // @Override
    // public void updateBunitsFromDatalake()
    //         throws DatalakeRequestException, DatalakeDataParseException {
    //     Bunit latestUpdateBunit = this
    //             .getOne(new QueryWrapper<Bunit>().orderByDesc("update_time").last("limit 1"));
    //     if (null == latestUpdateBunit) {
    //         List<Bunit> bunits = datalakeService.getAllBunits();
    //         bunits.forEach(bunit -> {
    //             if (!StringUtils.isBlank(bunit.getBunitNo())) {
    //                 this.save(bunit);
    //             }
    //         });
    //     } else {
    //         Map<DatalakeDataTypeEnum, List<Bunit>> bunits = datalakeService
    //                 .listBunitsByGreatEqualUpdateTime(latestUpdateBunit.getUpdateTime());
    //         bunits.get(DatalakeDataTypeEnum.CREATE).forEach(bunit -> this.save(bunit));
    //         bunits.get(DatalakeDataTypeEnum.UPDATE).forEach(bunit -> this.update(bunit,
    //                 new UpdateWrapper<Bunit>().eq("bunit_no", bunit.getBunitNo())));
    //         bunits.get(DatalakeDataTypeEnum.DELETE).forEach(bunit -> this
    //                 .remove(new QueryWrapper<Bunit>().eq("bunit_no", bunit.getBunitNo())));
    //     }
    // }
}
